<?php
namespace Admin\Controller;

class SettingController extends CommonController
{

    /**
     * 系统设置
     *
     * @param  void
     * @return void
     */
    public function index()
    {
        if (IS_POST) {
            $post = I('post.');
            unset($post['textfield']);
            unset($post['textfield2']);
            if (! empty($_FILES['start_image']['name']) || ! empty($_FILES['share_image']['name'])) {
                $file = D('File');
                $info = $file->upload($_FILES, C('PICTURE_UPLOAD'));
                if (! $info) {
                    $this->error($file->getError());
                }
                if (! empty($info['start_image'])) {
                    $post['start_image'] = $info['start_image']['url'];
                }
                if (! empty($info['share_image'])) {
                    $post['share_image'] = $info['share_image']['url'];
                }
            }

            foreach ($post as $key => $val) {
                setConfig($key, $val);
                if ($key == 'site_name'){
                    C('SITE_NAME', $val);
                }
            }
            $this->success('操作成功！');
        } else {
            $setting = M('Setting')->getField('set_key, set_value');
            $coupon = getCouponList(false);
            $article = array(1,2,3,4,5);
            $this->assign('coupon', $coupon);
            $this->assign('info', $setting);
            $this->display();
        }
    }
    
    /**
     * 会员特权
     *
     * @param void
     * @return void
     */    
    public function desc()
    {
        if (IS_POST) {
            $desc = I('post.member_desc');
            $price = I('post.vip_card_price');
            if (empty($desc)) {
                $this->error('信息不能为空!');
            }
            if (empty(intval($price))) {
                $this->error('会员卡价格不能为空!');
            }
            setConfig('vip_card_price', $price);
            setConfig('member_desc', $desc);
            $this->success('操作成功！');
        } else {
            $desc = getConfig('member_desc', false);
            $this->assign('member_desc', $desc);

            $price = getConfig('vip_card_price', false);
            $this->assign('vip_card_price', $price);

            $this->display();
        }
    }

    /**
     * 配送详情
     *
     * @param void
     * @return void
     */
    public function deliver()
    {
        if (IS_POST) {
            $desc = I('post.deliver_content');
            if (empty($desc)) {
                $this->error('信息不能为空!');
            }
            setConfig('deliver_content', $desc);
            $this->success('操作成功！');
        } else {
            $desc = getConfig('deliver_content', false);
            $this->assign('deliver_content', $desc);
            $this->display();
        }
    }
    
}